﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WikiBrodskyWcf
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WikiBrodscyWcfService" in both code and config file together.
    public class WikiBrodscyWcfService : IWikiBrodscyWcfService
    {
        public void DoWork()
        {
        }

        public void Stop()
        {
            Program.Working = false;
        }

        public void ConnectBotToServer(string serverName, string userName, string password, int workersStartPeriodMinutes)
        {
            #region validate input params
            if (string.IsNullOrWhiteSpace(serverName)) throw new ArgumentNullException("serverName");
            if (string.IsNullOrWhiteSpace(userName)) throw new ArgumentNullException("userName");
            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentNullException("password");
            #endregion            

            var pwd = password.Aggregate("", (current, c) => current + "*");

            Program.Log.InfoFormat("ConnectBotToServer: serverName = {0}, userName = {1}, password = {2}", serverName,userName,pwd);

            Program.MyBot.Connect(serverName, userName, password);

            Program.TimerPeriod = workersStartPeriodMinutes;
        }



        public void EnableDictionaryWorker(bool enable)
        {
            if (!Program.BotConnected)
            {
                Program.Log.Error("bot not connected");
                throw new Exception("bot not connected");
            }

            Program.Log.Info("EnableDictionaryWorker = " + enable);
            Program.DictionaryWorker = enable;
        }
    }
}
